SEEKGT, SEEKGE, SEEKEQ Statements ---------------------------------------------------------------------------- Action Causes the first matching record in an ISAM table to become the current record. Syntax SEEKGT # filenumber% , keyvalue, keyvalue SEEKGE # filenumber% , keyvalue, keyvalue SEEKEQ # filenumber% , keyvalue, keyvalue Remarks The SEEKGT, SEEKGE, and SEEKEQ statements cause the first matching record in the table, according to the current index, to become the current record. The following table shows which value of the current index column causes the record to become current for each statement. ----------------------------------------------------------------------------- Statement Current-index column value ---------------------------------------------------------------------------- SEEKGT Greater than keyvalue SEEKGE Greater than, or equal to, keyvalue SEEKEQ Equal to keyvalue The argument filenumber% is the number used in the OPEN statement to open the table. The argument keyvalue is an expression fewer than 256 characters long that is evaluated based on the operand condition in the SEEK operand keyword. If more than one keyvalue argument is specified, BASIC assumes the current index is based on the combination of their values. If no match is found, the current index position is at the end of the table and there is no current record. If the number of keyvalues is greater than the number of values that makes up the current index, BASIC generates the error message Syntax Error. No error is generated if the number of keyvalues is less than the number of values that makes up the current index. The seek either fails or is based on the keyvalues supplied. - SEEKEQ with too few keyvalues always fails. - SEEKGE with too few keyvalues is equivalent to a SEEKGE with the same arguments. - SEEKGT with too few keyvalues seeks for the first record that matches the keyvalues supplied. BASIC removes trailing spaces from strings used in a seek. Note The keyvalue expression must be explicitly typed if it is a DOUBLE or CURRENCY value. See Also MOVEFIRST, MOVELAST, MOVENEXT, MOVEPREVIOUS Statements; OPEN Example The following example uses the CREATETABLE statement to create a new table in an ISAM file and uses the SEEKGE, RETRIEVE, UPDATE, and INSERT statements to insert records into the file. It uses the LOF function to display the number of records in the new table and then deletes the table with DELETETABLE. The program uses a file called BOOKS.MDB, the sample ISAM file that SETUP copies to your disk. DEFINT A-Z TYPE BookRec IDNum AS DOUBLE ' Unique ID number for each book. Title AS STRING * 50 ' Book's title. Publisher AS STRING * 50 ' Book's publisher. Author AS STRING * 36 ' Book's author. Price AS CURRENCY ' Book's price. END TYPE CONST Database = "BOOKS.MDB" ' Name of the disk file. DIM Library AS BookRec ' Variable for current record. DIM MinPrice AS CURRENCY ' SEEK criteria. CLS DO INPUT "Display books that cost as much or more than "; MinPrice IF MinPrice < 0 THEN PRINT "Positive values only, please." LOOP UNTIL MinPrice > 0 ' Open existing table. LibraryFile = FREEFILE OPEN Database FOR ISAM BookRec "BooksStock" AS LibraryFile CREATEINDEX LibraryFile, "Library", 0, "Price" SETINDEX LibraryFile, "Library" ' Create and open a new table. NewFile = FREEFILE OPEN Database FOR ISAM BookRec "PricyBooks" AS NewFile ' Fill new table with records for all books with price >= MinPrice. SEEKGE LibraryFile, MinPrice DO RETRIEVE LibraryFile, Library INSERT NewFile, Library MOVENEXT LibraryFile LOOP UNTIL EOF(LibraryFile) ' First time through loop get price increase; ' second time display new price. FOR count = 1 TO 2 CLS PRINT SPC(18); LOF(NewFile); "books cost at least "; PRINT USING ("$###.##"); MinPrice PRINT " ID Number"; SPC(3); "Title"; SPC(20); "Author"; PRINT SPC(11); "Publisher"; SPC(10); "Price" VIEW PRINT 3 TO 20 MOVEFIRST NewFile DO RETRIEVE NewFile, Library PRINT Library.IDNum; " "; LEFT$(Library.Title, 20); IF LEN(RTRIM$(Library.Title)) > 20 THEN PRINT "... "; ELSE PRINT " "; END IF PRINT LEFT$(Library.Author, 15); " "; PRINT LEFT$(Library.Publisher, 16); " "; PRINT USING ("$###.##"); Library.Price MOVENEXT NewFile LOOP UNTIL EOF(NewFile) IF count = 1 THEN VIEW PRINT 20 TO 24. LOCATE 20, 1 DO INPUT "Increase cost by how much (0-100%)"; increase IF increase < 0 OR increase > 100 THEN PRINT "Illegal value" LOOP UNTIL increase >= 0 AND increase <= 100 ' Update records in PricyBooks. MOVEFIRST NewFile DO RETRIEVE NewFile, Library Library.Price = (Library.Price * (100 + increase)) - 100 ' Overwrite record with increased price. UPDATE NewFile, Library CHECKPOINT' Force ISAM to flush the buffer to disk. MOVENEXT NewFile LOOP UNTIL EOF(NewFile) END IF VIEW PRINT 1 TO 19 NEXT count ' Destroy index and temporary table, close files. DELETEINDEX LibraryFile, "Library" CLOSE DELETETABLE Database, "PricyBooks"